package cn.maihe.elg.operation.supports.electronicseal.anne.service.impl;

import cn.maihe.elg.operation.config.AnneSignConfig;
import cn.maihe.elg.operation.config.ElgConfig;
import cn.maihe.elg.operation.exception.SystemRuntimeException;
import cn.maihe.elg.operation.supports.electronicseal.anne.AnneServiceName;
import cn.maihe.elg.operation.supports.electronicseal.anne.BaseAnneSignService;
import cn.maihe.elg.operation.supports.electronicseal.anne.bean.annesign.account.IndividualRealNameSyncRequest;
import cn.maihe.elg.operation.supports.electronicseal.anne.bean.annesign.account.IndividualRealNameSyncRequestBody;
import cn.maihe.elg.operation.supports.electronicseal.anne.bean.annesign.account.IndividualRealNameSyncResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

/**
 * @Description 个人实名同步
 * @Author WJH
 * @Date 2021/08/13
 */
@Slf4j
@Service
public class IndividualRealNameSyncService extends BaseAnneSignService<IndividualRealNameSyncRequest, IndividualRealNameSyncResponse> {


    public IndividualRealNameSyncService(AnneSignConfig anneSignConfig, ElgConfig elgConfig) {
        super(anneSignConfig, elgConfig);
    }

    @Override
    protected AnneServiceName serviceName() {
        return AnneServiceName.real_name_sync;
    }


    /**
     * 发起合同签署
     * 创建合同-发起合同签署-自动合同签署|手动签署
     *
     * @param body
     */
    public Long realNameSync(IndividualRealNameSyncRequestBody body) {

        Assert.notNull(body, "实名同步请求对象不能为空");
        Assert.hasText(body.getName(), "姓名不能为空");
        Assert.hasText(body.getIdCard(), "身份证号不能为空");
        Assert.hasText(body.getMobile(), "手机号码不能为空");

        IndividualRealNameSyncRequest request = this.buildBaseReq();
        request.setBody(body);

        try {
            IndividualRealNameSyncResponse response = this.doPost(request);
            log.info("个人实名同步记录ID individualId:{}", response.getBody().getIndividualId());
            return response.getBody().getIndividualId();
        } catch (Exception e) {
            log.error("个人实名同步失败:{}", e.getMessage(), e);
            throw SystemRuntimeException.error("个人实名同步失败" + e.getMessage(), e);
        }

    }


}
